import {callApiRequest, batchCallApiRequest, callApiRequestNotToast,} from '../utils/api'
import constant from '../utils/constants'
import LocalStorageService from "../utils/LocalStorageService";
// const BaseUrl = constant.TestUrl4
const BaseUrl = constant.BaseUrl

const localUrl = constant.localUrl

// 辅助函数
export const reqPattern = async (url, path, verb, action, params, toast = true) => {

    let end = `${url}/${path}/${action}`
    if (path === '') {
        end = `${url}/${action}`
    }

    if (toast) {
        let resp = await callApiRequest(end, {
            verb: `${verb}`,
            params: params,
        })
        return resp
    } else {
        let resp = await callApiRequestNotToast(end, {
            verb: `${verb}`,
            params: params,
        })

        return resp
    }

}

export const postGoReq = (action, params, toast = true) => reqPattern(BaseUrl, 'try/go', 'post', action, params, toast,)
const postApiReq = (action, params, toast = true) => reqPattern(BaseUrl, 'apis', 'post', action, params, toast,)
const postLavReq = (action, params, toast = true) => reqPattern(BaseUrl, 'lav', 'post', action, params, toast,)

// const postAdminReq = (action, params, toast = false) => reqPattern('http://123.207.85.242:7555', '', 'post', action, params, toast,)
const postAdminReq = (action, params, toast = false) => callApiRequestNotToast('http://123.207.85.242:7555/addgamevideo', {
    verb: 'post',
    params: params,
})

// token no need
// 注册请求
export const createGoUserReq = (params) => postGoReq('reg', params)
// 登录请求
export const loginGoUserReq = (params) => postGoReq('login', params)
// 新闻列表
// export const fetchNewsListReq = (params) => postGoReq('newslist', params)
export const fetchNewsListReq = (params) => postGoReq('newsheadline', params)
// 新浪新闻列表
export const fetchSinaNewsListReq = async (params) => {

    let resp = await callApiRequestNotToast(localUrl + '/getnews', {
        verb: 'get',
        params: params,
    })

    return resp
}

// 新闻详情
export const fetchNewsDetailReq = (params) => postGoReq('newsdetail', params)

// token
// 刷新 token 请求
export const refreshTkReq = (params) => postGoReq('rtoken', params)
// 登出请求
export const logoutReq = (params) => postApiReq('logout', params)
// 用户信息请求
export const getUserDetailReq = (params, toast) => postApiReq('getuserdetail', params, toast)
// 关注列表
export const getFollowingReq = (params) => postApiReq('getfollowing', params)
// 关注请求
export const addFollowReq = (params) => postApiReq('following', params)
// 取消关注请求
export const cancelFollowReq = (params) => postApiReq('unfollowing', params)
// 签到
export const checkInReq = (params) => postApiReq('signquest', params)
// 实名验证请求
export const realInfoVerifyReq = (params) => postApiReq('realinfo', params)
// 提现记录
export const withdrawLogsReq = (params) => postApiReq('takeoutlogs', params)
// 提现请求
export const withdrawReq = (params) => postApiReq('trytakeout', params)
// 获取用户账户信息
export const fetchAccountInfoReq = (params) => postApiReq('takeoutinfo', params)
// 保存用户账户信息
export const saveAccountInfoReq = (params) => postApiReq('savetakeoutinfo', params)
// 充值记录请求
export const fetchPayDataReq = (params) => postApiReq('getdetailgoldrecharge2', params)
// 消费记录请求
export const fetchConsumeDataReq = (params) => postApiReq('consumelog', params)
// 道具消费记录请求
export const fetchItemConsumeLogReq = (params) => postApiReq('getdetailpropcost', params)
// 金币消费记录请求
export const fetchCoinConsumeLogReq = (params) => postApiReq('getdetailservercost2', params)
// 申请成为主播请求
export const applyStarReq = (params) => postApiReq('applystar', params)
// 用户获取官方通知
export const fetchOfficialNoticeReq = (params) => postApiReq('officalnotice', params)
// 用户获取系统通知
export const fetchSystemInfoReq = (params) => postApiReq('sysinfos', params)
// 重置密码请求
export const resetPasswordReq = (params) => postApiReq('resetpwd', params)
// 忘记密码
export const forgetPasswordReq = (params) => postGoReq('verifyresetpwd', params)
// 修改昵称
export const changeNameReq = (params) => postApiReq('changename', params)
// 上传头像
export const uploadAvatarReq = (params) => postApiReq('ca/changeavatar', params)
// 上传视频
export const uploadVideoReq = (params) => postAdminReq('addgamevideo', params)
// 用户反馈
// export const feedbackReq = (params) => reqPattern('http://test.youtoball.com', 'app/apis/fk', 'post', 'addfeedback', params, true)
export const feedbackReq = (params) => postApiReq('/fk/addfeedback', params, true)
// 获取反馈列表
export const feedbackListReq = (params) => postApiReq('getfeedback', params, true)
// h5 微信充值
export const wechatReq = (params) => reqPattern('http://www.youtoball.com/app', 'apis', 'post', 'wxh5recharge2', params, true,)
// 确认微信确诊订单
export const checkWechatOrderReq = (params) => postApiReq('wxcheckrecharge2', params, false)
// 获取注册验证码
export const getYZMReq = (params) => postGoReq('sendyz', params, true,)


//VIP
// 购买VIP会员
export const buyVipReq = (params) => postApiReq('buyvip', params)

// live
// 开播
export const openLiveReq = (params) => postLavReq('openlive', params)
// 创建房间 (测试)
export const openRoomReq = (params) => postLavReq('suchatestofgolang', params = {})
// 主播暂离/主播关闭直播
// 直接删除直播频道(后台)
export const deleteLiveReq = params => postLavReq('dellive', params)
// 直播房间列表
// export const fetchLiveListReq = params => postLavReq('livelist', params)
export const fetchLiveListReq = params => postGoReq('livelist', params)
// 直播房间列表(后台) 带过滤条件
export const fetchLiveListWithQueryReq = params => postLavReq('livequerylist', params)
// 获取直播间详情 拉流地址
export const fetchLiveDetailReq = params => postLavReq('livedetail', params)
// 主播的排行榜
export const fetchStarRankListReq = params => postApiReq('getstarranklist', params)
// 主播的排行榜 no token
export const fetchStarRankListNoTokenReq = params => postGoReq('getstarranklist', params)

// vod
export const starOfflineReq = (params) => postLavReq('afkorofflinelive', params)
// 修改 vod 名字 描述
export const modifiedVodNameReq = (params) => postLavReq('modvodname', params)
// 删除 vod
export const deleteVodReq = (params) => postLavReq('delvod', params)
// 增加 vod
export const addVodReq = (params) => postLavReq('addvod', params)
// 点播视频列表
// http://123.207.85.242/app/try/go/getgamevideolist
// export const fetchVodListReq = params => postLavReq('vodlist', params)
export const fetchVodListReq = params => postGoReq('getgamevideolist', params)

// 点播视频列表(后台) 带过滤条件
export const getVodCommentReq = params => postGoReq('getvideocomment', params, true,)
export const doCommentVod = params => postApiReq('videocomment', params, true,)
// 点赞视频
// 获取视频详情
export const getVodDetailReq = params => postGoReq('getvideobyid', params, false,)

export const fetchVodListWithQueryReq = params => postLavReq('vodquerylist', params)
// 禁用/启用 vod
export const muteOrActiveVodReq = params => postLavReq('mutevod', params)
// 禁用/启用 vod
export const muteOrActiveLiveReq = params => postLavReq('mutelive', params)
// 获取 vod 详情
export const fetchVodDetailReq = params => postLavReq('voddetail', params)
// 观看直播获取积分
export const getVodExpReq = params => postApiReq('rewardlookzhibo', params, false)


// game
// 获取比赛列表
// export const fetchGameListReq = (params) => postLavReq('gamelist', params)
export const fetchGameListReq = (params, toast) => postGoReq('getfootballmatchlistbydate', params, toast)
// 获取比赛详情
export const fetchGameDetailReq = params => postGoReq('getfootballdetail', params, false)
// 获取比赛列表更新
export const fetchGameListLiveReq = (params) => postGoReq('getfootballlive', params, false)
// 获取比赛盘口数据
export const fetchGameOddsHistoryReq = (params) => postGoReq('getfootballoddhistory', params, false,)
// 比赛聊天室创建
export const getGameRoomChatTokenReq = params => postLavReq('gamechatroom', params)
// 获取是否有直播
export const getGameLiveReq = params => postGoReq('getzhibo', params, false,)
// 获取直播列表
export const getGameLiveListReq = params => postGoReq('getgamezhibolist', params, false,)
// 获取比赛分享
export const getGameIntelligenceReq = params => postGoReq('getfootballintelligence', params, false)
// 获取比赛情报
export const getGameAnalysis = params => postGoReq('getfootballanalysis', params, false,)
// 获取盘口列表
export const getGameOddsList = params => postGoReq('getchupan', params, false,)
// 获取比赛竞猜数据
export const matchGuessReq = params => postApiReq('guessmatch', params,)
export const fetchMatchGuessReq = params => postApiReq('getguessrate', params, false)
// ai预测
export const fetchGameAiReq = params => postApiReq('getmatchaidata', params, false)
export const fetchGameAiBuyReq = params => postApiReq('getmatchaidata', params, false)
// 购买ai预测
export const buyGameAiReq = params => postApiReq('buyai2', params, true)
// 关注请求
export const markGameReq = params => postApiReq('guanzhu', params, true)
// 关注列表请求
export const fetchMarkGameListReq = params => postApiReq('/getguanzhu', params, true)
// 聊天获取经验
export const getChatExpReq = params => postApiReq('rewardliaotian', params, false)
// 获取聊天室token
export const getChatTokenReq = params => postApiReq('getchattoken', params, false)
export const getVisitorChatTokenReq = params => postGoReq('getchattoken', params, false)
// 发送聊天消息
export const sendChatMsgReq = params => postApiReq(window.location.href.includes('basketball') ? 'sendzhibomsg' : 'sendzhibomsg2', params, false)
// export const sendBaseketballChatMsgReq = params => postApiReq('sendzhibomsg', params, false)
// 获取单场比赛是否有直播
export const getIsGameVodLiveReq = params => postGoReq('getgamezhibo', params, false)


// 消息
// 获取消息状态
export const fetchMsgStateReq = params => postApiReq('getmsgstate', params, false)
// 获取用户消息
export const fetchUserMsgReq = params => postApiReq('getmsg', params, false)
// 获取系统消息
export const fetchSysMsgReq = params => postApiReq('getsysmsg', params, false)
// 获取vip消息
export const fetchVipMsgReq = params => postApiReq('getvipmsg', params, false)

// 话题
// 添加话题
export const addTopicReq = params => postApiReq('ht/addhuati', params, true)
// export const addTopicReq = params => postApiReq('ca/addhuati', params, true)
// export const addTopicReq = params => reqPattern('http://123.207.85.242', 'houtai', 'post', 'addhuati', params, true)
// 删除话题
// export const deleteTopicReq = params => reqPattern('http://123.207.85.242', 'houtai', 'post', 'delhuati', params, true)
// 获取话题 (单条)
export const getTopicDetailReq = params => postGoReq('gethuatibyid', params, true)
// 获取话题 (评论时间排序)
export const getTopicListByCommentTimeReq = params => postGoReq('gethuatibycomment ', params, true)
// 获取话题 (发表时间排序)
export const getTopicListByReleaseReq = params => postGoReq('gethuati', params, true)
// 获取话题 (按精和发表时间排序)
export const getTopicListByJingHua = params => postGoReq('gethuatibyjing', params, true)
// 获取话题评论
export const getCommentReq = params => postGoReq('getcomment', params, true)
// 发表评论
export const commentReq = params => postApiReq('huaticomment', params, true)
// 赞评论
export const zanCommentReq = params => postApiReq('huatizan', params, true)
// 获取我的话题消息状态
export const getMyTopicStateReq = params => postApiReq('getwodestate', params, false)
// 获取我的视频消息状态
export const getMyVodStateReq = params => postApiReq('getwodevideostate', params, false)
// 获取我的话题消息
export const getMyTopicMsgReq = params => postApiReq('getwodeplhf', params, true)
// 获取我的视频消息
export const getMyVodMsgReq = params => postApiReq('getwodevideoplhf', params, true)
// 获取我的话题
export const getMyTopicReq = params => postApiReq('getwodehuati', params, true)
// 删除评论
export const deleteCommentReq = params => postApiReq('delcomment', params, true)
// 删除视频评论
export const deleteVodCommentReq = params => postApiReq('delvideocomment', params, true)
// 删除话题
export const deleteTopicReq = params => postApiReq('delhuati', params, true)
// 举报评论
export const reportCommentReq = params => postApiReq('jubao', params, true)
// 获取评论总数
export const doGetTopicTotal = params => postGoReq('gethuatitotal', params, false)

// 分享请求
export const shareReq = params => postGoReq('weixinappshare', params, false)

// 获取任务信息
export const getTaskInfoReq = params => postApiReq('gettaskinfo2', params,true)

// 提交邀请码
export const submitYQMReq = params => postApiReq('useyqcode', params, true)

// 近期预测
export const getAIResultListReq = params => postGoReq('getjinqiyuce2', params, false)
// 热门预测
export const getHotAiListReq = params => postGoReq('getremenyuce', params, true)
// 我购买的预测(未赛)
export const getMyAIListNotStartReq = params => postApiReq('getbuyweisai', params, true)
// 我购买的预测(已赛)
export const getMyAIListFinishedReq = params => postApiReq('getbuyyisai', params, true)

// 欧冠
export const getOGPoint = params => postGoReq('pcgetjifen', params, true,)
export const getOGShooter = params => postGoReq('pcgetsheshou', params, true)
export const getOGMatch = params => postGoReq('pcgetbisai', params, true,)

// 礼物
export const getMyGiftReq = params => postApiReq('buyproppage2', params, true)
export const buyGiftReq = params => postApiReq('buyprop', params, true)

// 方案
export const getPlanListReq = params => postGoReq('getscheme', params, false,)
export const getPlanDetailReq = params => postApiReq('getschemedetail', params, false,)
export const zanPlanReq = params => postApiReq('jubaoorzan', {...params, Handle: 1,}, true,)
export const jubaoPlanReq = params => postApiReq('jubaoorzan', {...params, Handle: 2,}, true,)
export const buyPlanReq = params => postApiReq('buyscheme', params, true,)
export const sendPlanGiftReq = params => postApiReq('gifttouser', params, true,)
export const getHasPlanReq = params => postGoReq('isshowscheme', params, false,)
export const getMyPlanReq = params => postApiReq('giftorbuy', params, true,)
export const getApplyPlanProFlagReq = params => postApiReq('applyresult', params, true,)
export const submitApplyPlanProReq = params => postApiReq('applyspecialist', params, true,)
export const setPlanProDetailReq = params => postApiReq('setspecialistinfo', params, true,)
export const getPlanProDetailReq = params => postApiReq('getspecialistinfo', params, true,)
export const getPlanProListReq = params => postApiReq('getspecialistdetail', params, true)
export const addProPlanReq = params => postApiReq('addscheme', params, true)
export const deleteProPlanReq = params => postApiReq('deletescheme', params, true)
export const getMyProIncomeReq = params => postApiReq('getschemeincome', params, true)
export const getIsNewTogetherUserReq = params => postApiReq('checkyindao', params, true)
// 篮球
// 150./try/go/getmatchlanqiu 获取篮球比赛列表
//
// 151./try/go/getmatchlanqiusaicheng 获取篮球比赛赛程
// date string //日期格式未20060102
//
// 151./try/go/getmatchlanqiusaiguo 获取篮球比赛赛果
// date string //日期格式未20060102
//
// 152./try/go/getmatchlanqiulive 获取篮球比赛正在进行的，也作为定时刷新
export const getBasketballGameListAllReq = params => postGoReq('getmatchlanqiu', params, false)
export const getBasketballGameListLiveReq = params => postGoReq('getmatchlanqiulive', params, false)
export const getBasketballGameListReq = params => postGoReq('getmatchlanqiusaicheng', params, false)
export const getBasketballGameResultReq = params => postGoReq('getmatchlanqiusaiguo', params, false)
export const getBasketballGameDetailReq = params => postGoReq('getmatchlanqiuzhibo', params, false)
export const getBasketballGameFollowReq = params => postApiReq('getguanzhulanqiu', params, false)
export const followBasketballGameReq = params => postApiReq('guanzhulanqiu', params)
export const getBasketballLiveStatusReq = params => postGoReq('getlanqiulivetextstatus', params)
export const getBasketballLiveDetailReq = params => postGoReq('getlanqiulivetext', params, false)
export const getBasketballStatReq = params => postGoReq('getlanqiudetailcount', params)

// 一起看
export const getVoteDataReq = params => postApiReq('getchatinfo', params, false)
export const getVisitorVoteDataReq = params => postGoReq('getchatinfo', params, false)
export const votTeamReq = params => postApiReq('usersupport', params)
export const getHeatRankReq = params => postApiReq('supporttop', params)
export const getFuliDetailReq = params => postApiReq('getfuli', params)
export const getFuliResultReq = params => postApiReq('getuserroomblock', params, false)
export const getMyFuli = params => postApiReq('getmyblock', params)
export const getMyFuliCount = params => postApiReq('getmyblockcount', params)
export const sellPiece = params => postApiReq('saleblock', params)
export const changePiece = params => postApiReq('conversionblock', params)
export const getFuliRank = params => postApiReq('getblocktop', params, false)
export const zanzuReq = params => postApiReq('usersponsor', params,)
export const getMyFuliRecordReq = params => postApiReq('getmyblockbilldetail', params,)
// 游戏
export const getGameLoginInfo = params => postGoReq('gamelogin', params)
export const getGameVisitorInfo = params => postGoReq('gettaskpageurl', params)

// 包厢
export const getVipRoomInfoReq = params => postApiReq('getvipboxinfo', params)
export const addVipRoomReq = params => postApiReq('createvipbox', params)

// export const getQuizListReq = params => postHoutaiReq('getproblem', params, true)
export const getQuizListReq = params => reqPattern('http://123.207.85.242', 'houtai', 'post', 'getproblem', params,)
// 活跃度埋点函数
export const hitReq = params => postGoReq('userhandle', params, false)
// 用户行为埋点函数
export const behaviorReq = params => postGoReq('loginthreehandle', params,false)
export const addHitCountReq = params => postGoReq('tongjidetail', params, false,)
export const addHitCount = (key, data = {title: '', id: 0,}) => {
    // Flag  int    `binding:"min=1"`    //1=视频，2=资讯，3=社区
    // Id    int    `binding:"min=0"`    //0=资讯,1以上其他
    // Title string `binding:"required"` //标题

    // const {
    //     title,
    //     id,
    // } = data
    const flags = {
        news: 2,
        topic: 3,
        video: 1,
    }
    addHitCountReq({
        Flag: flags[key],
        Id: data.id,
        Title: data.title,
    })
}
export const getHotReq = params => postGoReq('gethotgame', params, true)
// 评选
export const getVoteListReq = (params) => postApiReq('getselection', params, true)
export const gradePlayerReq = (params) => postApiReq('userselection1', params, true)
export const voteBestLineupReq = (params) => postApiReq('userselection2', params, true)
export const voteForecastReq = (params) => postApiReq('userselection3', params, true)
export const getVoteResultReq = (params) => postApiReq('getselectionresult', params, true)
// 商城
export const getMallListReq = (params) => postGoReq('getproducts', params, true)
export const getMallHotReq = (params) => postGoReq('getproductshot', params, true)
export const getMallDetailReq = (params) => postGoReq('getproductbyid', params, true)
export const submitMallDealReq = (params) => postApiReq('addproductdeal', params, true)
export const getMallRecordReq = (params) => postApiReq('getproductdeal', params, true)
export const getBeanListReq = (params) => postApiReq('getyingdoudeal', params, true)
export const getLastOrderReq = (params) => postApiReq('getproductaddress', params, true)
// 任务中心
export const taskInfoReq = (params) => postApiReq('donewtask', params, false)
// 获取下载地址
export const getDownloadUrlReq = (params) => postGoReq('getuseurl', params, false)
// 获取签到信息
export const getSignInfoReq = (params) => postApiReq('getsigninfo', params, false)
export const signReq = (params) => postApiReq('eurocupsignin', params, false)
// 欧洲杯相关
export const getEuroGameReq = (params) => postApiReq('getozbmatch', params, false)
export const getEuroGameVisitorReq = (params) => postGoReq('getozbmatch', params, false)
export const getMyEuroPlanReq = (params) => postApiReq('geteurocuppage', params, false)
export const getMyEuroPlanListReq = (params) => postApiReq('geteurocupscheme', params, false)
export const getEuroPointReq = (params) => postGoReq('geteurocupjifeng', params, false)
export const getEuroShooterRankReq = (params) => postGoReq('geteurocupsheshou', params, false)
export const getEuroPlanDetailReq = (params) => postApiReq('geteurocupschemedetail', params, false)
export const getEuroPlanRankReq = (params) => postApiReq('geteurosupporttop', params, false)
export const zanEuroPlanReq = (params) => postApiReq(
    'eurocupschemejubaoorzan',
    {...params, Txt: '',},
    false
)
export const jubaoEuroPlanReq = (params) => postApiReq(
    'eurocupschemejubaoorzan',
    {...params, Txt: 'jubao',},
    false
)
export const supportEuroPlanReq = (params) => postApiReq('eurocupsupport', params, false)
export const getDouStatusReq = (params) => postApiReq(
    'geteurowinred',
    {...params, Flag: 1,},
    false
)
export const getDouReq = (params) => postApiReq(
    'geteurowinred',
    {...params, Flag: 0,},
    false
)
export const getEuroQuestionnaire = (params) => postApiReq('getquestionnaire', params)
export const submitEuroQuestionnaire = (params) => postApiReq('commitquestionnaire', params)
export const getEuroQuestionnaireSubmitStatusReq = (params) => postApiReq('isquestionnaire', params, false)

export const checkGuideReq = (params) => postApiReq('getguidance', params, false,)
export const finishGuideReq = (params) => postApiReq('setguidance', params, true)

// 合并请求
// 所有比赛包含 status=live status=early
export const fetchGameListAllReqList = (params) => batchCallApiRequest([fetchGameListReq({date: params.date, status: params.status[0]}), fetchGameListReq({date: params.date, status: params.status[1]})])
// 主页数据请求
// export const fetchHomeDataReqList = () => batchCallApiRequest()


// 纳米api数据接口转发


